package com.pcrtool.calculateequipment.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pcrtool.calculateequipment.entity.UnitData;
import com.pcrtool.calculateequipment.service.UnitDataService;
import com.pcrtool.pcrtoolcommon.utils.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yzs
 * @since 2021-12-30
 */
@Api(tags = "角色")
@RestController
@RequestMapping("/calculateequipment/unit-data")
public class UnitDataController {
    @Autowired
    UnitDataService unitDataService;

//  分页查询
    @PostMapping("findPage/{current}/{limit}")
    public R getUnit(@PathVariable Long current, @PathVariable Long limit,@RequestBody(required = true) UnitData unitData){
        Page<UnitData> page = unitDataService.findPage(current, limit, unitData);
        return R.ok().put("data",page);
    }

//  更新数据
    @PostMapping("update/recommand")
    public R update(Collection<UnitData> unitDataCollection){
        if (unitDataService.saveOrUpdateBatch(unitDataCollection)){
            return R.ok();
        } else {
            return R.error();
        }
    }

    @GetMapping("getAll")
    public R getAll(){
        List<UnitData> list = unitDataService.list(null);
        return R.ok().put("data",list);
    }
}

